package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/***
 * 分类接口
 */
@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"unchecked", "rawtypes"})
/***
 * 分类接口
 */
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;


	/**
	 * 获取全部分类信息
	 * @return
	 */
	@GetMapping("/getBaseCategoryList")
	public Result getBaseCategoryList() {
		List baseCategoryList = baseCategoryService.getBaseCategoryList();
		return Result.ok(baseCategoryList);
	}

	/**
	 * 根据一级分类获取属性列表
	 * @param category1Id 一级分类的id
	 * @return 属性列表
	 */
	@GetMapping("/findAttribute/{category1Id}")
	public Result<List<BaseAttribute>> getAttribute(@PathVariable("category1Id") Long category1Id){
		return Result.ok(baseCategoryService.getAttribute(category1Id));
	}

	/**
	 * 查询置顶前七的三级分类
	 * @param category1Id
	 * @return
	 */
	@GetMapping("/findTopBaseCategory3/{category1Id}")
	public Result findTopBaseCategory3(@PathVariable(value = "category1Id") Long category1Id){
		return Result.ok(baseCategoryService.findTopBaseCategory3(category1Id));
	}

	/**
	 * 根据一级分类id查询二级分类和三级分类
	 * @param category1Id
	 * @return
	 */
	@GetMapping("/getBaseCategoryList/{category1Id}")
	public Result getBaseCategoryList(@PathVariable(value = "category1Id") Long category1Id){
		return Result.ok(baseCategoryService.getBaseCategoryList(category1Id));
	}

}

